package com.dajibang.activity;




import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.RadioButton;
import android.widget.TabHost;

import com.dajibang.R;

public class MainActivity extends TabActivity implements
		OnCheckedChangeListener {

	private TabHost mTabHost;
	private Intent mLocateIntent;
	private Intent mTraceIntent;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_main);
		
		this.mLocateIntent = new Intent(this, YidingMainActivity.class);
		this.mTraceIntent = new Intent(this, RecordTraceActivity.class);

		((RadioButton) findViewById(R.id.radio_button_locate))
				.setOnCheckedChangeListener(this);
		((RadioButton) findViewById(R.id.radio_button_trace))
				.setOnCheckedChangeListener(this);
		
		setupIntent();

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}

	@Override
	public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
		if (isChecked) {
			switch (buttonView.getId()) {
			case R.id.radio_button_locate:
				this.mTabHost.setCurrentTabByTag("LOCATE_TAB");
				break;
			case R.id.radio_button_trace:
				this.mTabHost.setCurrentTabByTag("TRACE_TAB");
				break;
			}
		}
	}
	
	private void setupIntent() {
		this.mTabHost = getTabHost();
		TabHost localTabHost = this.mTabHost;

		localTabHost.addTab(buildTabSpec("LOCATE_TAB", R.string.nav1,
				R.drawable.ic_launcher, this.mLocateIntent));

		localTabHost.addTab(buildTabSpec("TRACE_TAB", R.string.nav2,
				R.drawable.ic_launcher, this.mTraceIntent));

	}
	

	private TabHost.TabSpec buildTabSpec(String tag, int resLabel, int resIcon,
			final Intent content) {
		return this.mTabHost
				.newTabSpec(tag)
				.setIndicator(getString(resLabel),
						getResources().getDrawable(resIcon))
				.setContent(content);
	}
	
}
